package com.vader.admin.controller;

import com.vader.admin.entity.DO.BaseTaskPublish;
import com.vader.admin.entity.Query.BaseTaskPublishQuery;
import com.vader.admin.service.BaseTaskPublishService;
import com.vader.common.entity.CommonResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 活动发布信息(BaseTaskPublish)表控制层
 *
 * @author Vader
 * @since 2021-10-06 12:46:39
 */
@RestController
@RequestMapping("baseTaskPublish")
public class BaseTaskPublishController {
    /**
     * 服务对象
     */
    @Resource
    private BaseTaskPublishService baseTaskPublishService;

    /**
     * 分页查询
     *
     * @param baseTaskPublish 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
    @GetMapping
    public CommonResponse<Page<BaseTaskPublish>> queryByPage(BaseTaskPublish baseTaskPublish, PageRequest pageRequest) {
        return CommonResponse.success(this.baseTaskPublishService.queryByPage(baseTaskPublish, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public CommonResponse<BaseTaskPublish> queryById(@PathVariable("id") Long id) {
        return CommonResponse.success(this.baseTaskPublishService.queryById(id));
    }

    /**
     * 活动发布
     *
     * @param baseTaskPublishQuery 实体
     * @return 新增结果
     */
    @PostMapping("/taskPublish")
    public CommonResponse<BaseTaskPublish> taskPublish(BaseTaskPublishQuery baseTaskPublishQuery) {
        BaseTaskPublish baseTaskPublish = BaseTaskPublish.from(baseTaskPublishQuery);
        return CommonResponse.success(this.baseTaskPublishService.insert(baseTaskPublish));
    }

    /**
     * 编辑数据
     *
     * @param baseTaskPublish 实体
     * @return 编辑结果
     */
    @PutMapping("/editTask")
    public CommonResponse<BaseTaskPublish> edit(BaseTaskPublish baseTaskPublish) {
        return CommonResponse.success(this.baseTaskPublishService.update(baseTaskPublish));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public CommonResponse<Boolean> deleteById(Long id) {
        return CommonResponse.success(this.baseTaskPublishService.deleteById(id));
    }

}

